home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / rayshade / libray / libtext / marble.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  65 lines

  1. /*
  2.  * marble.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: marble.c,v 4.0 91/07/17 14:43:06 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    marble.c,v $
  19.  * Revision 4.0  91/07/17  14:43:06  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "texture.h"
  24. #include "marble.h"
  25.  
  26. MarbleText *
  27. MarbleCreate(mapname)
  28. char *mapname;
  29. {
  30.     MarbleText *marble;
  31.  
  32.     marble = (MarbleText *)Malloc(sizeof(MarbleText));
  33.     if (mapname)
  34.         marble->colormap = ColormapRead(mapname);
  35.     else
  36.         marble->colormap = (Color *)NULL;
  37.     return marble;
  38. }
  39.  
  40. void
  41. MarbleApply(marble, prim, ray, pos, norm, gnorm, surf)
  42. MarbleText *marble;
  43. Geom *prim;
  44. Ray *ray;
  45. Vector *pos, *norm, *gnorm;
  46. Surface *surf;
  47. {
  48.     Float val;
  49.     int index;
  50.  
  51.     val = Marble(pos);
  52.     if (marble->colormap) {
  53.         index = (int)(255. * val);
  54.         surf->diff.r *= marble->colormap[index].r;
  55.         surf->diff.g *= marble->colormap[index].g;
  56.         surf->diff.b *= marble->colormap[index].b;
  57.         surf->amb.r *= marble->colormap[index].r;
  58.         surf->amb.g *= marble->colormap[index].g;
  59.         surf->amb.b *= marble->colormap[index].b;
  60.     } else {
  61.         ColorScale(val, surf->amb, &surf->amb);
  62.         ColorScale(val, surf->diff, &surf->diff);
  63.     }
  64. }
  65.